//
//  YMWiFiTools.swift
//  ViomiSystemAuth
//
//  Created by 陈狄夫 on 2021/5/14.
//

import Foundation
import SystemConfiguration.CaptiveNetwork

public class YMWiFiTools: NSObject {
    public class func getCurrentWiFiSsid () -> String? {
        if let interface : CFArray = CNCopySupportedInterfaces() {
                    for i in 0..<CFArrayGetCount(interface) {
                        let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interface, i);
                        let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
                        if let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString), let interfaceData = unsafeInterfaceData as? [String : AnyObject] {
                            if let ssid =  interfaceData["SSID"] as? String {
                                return ssid
                            }
                        }
                    }
                }
                return nil;
    }
}
